<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class GoodsType extends Model
{
    //
    protected $fillable = [
        'name',
        'seller_id',
        'status',
        'sort',
        'parent_id',
        'is_parent'
    ];
    protected $casts = [
        'status'=>'boolean'
    ];
    public function children()
    {
        return $this->hasMany(self::class, 'parent_id', 'id')->orderBy('sort','desc');
    }

    public function parent()
    {
        return $this->belongsTo(self::class, 'parent_id', 'id');
    }
    public function goods(){
        return $this->hasMany(Goods::class,'type_id','id');
    }
}
